package md.frolov.bible;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import md.frolov.bible.initializers.BookInitializator;
import md.frolov.bible.initializers.IInitializator;
import md.frolov.bible.initializers.IndexInitializator;
import md.frolov.bible.initializers.InitializationException;

import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	private static final String PERSPECTIVE_ID = "md.frolov.bible.perspective";

    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        return new ApplicationWorkbenchWindowAdvisor(configurer);
    }

	public String getInitialWindowPerspectiveId() {
		return PERSPECTIVE_ID;
	}

	/**
	 * All initialization is made here
	 */
	@Override
	public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
		
		List<IInitializator> list = new ArrayList<IInitializator>();
		
		list.add(new IndexInitializator());
		list.add(new BookInitializator());
		
		for (Iterator<IInitializator> it = list.iterator(); it.hasNext();) {
			try{
				System.out.println("initializing...");
				it.next().initialize();
			} catch (InitializationException e){
				e.printStackTrace();
			}
		}
	}

	
}
